_obj = _this select 0;
_aiSide = _this select 1;
_wait = _this select 2;
_marker = _this select 3;

/*
	In the beginning we start this script a lot to grab the flags.
	There for we need to first wait betwen each so they don't crash into eachother.
	Second decide if we can afford, third if its closer to the enemy we probably should leave it
	or we could try send some extra troops.
*/

sleep _wait;
_x = floor ((random 400) - (random 400));
_y = floor ((random 400) - (random 400));
_pos = getpos _obj;
_pos = [(_pos select 0) + _x, (_pos select 1) +_y,0];

"ai_sf_LZ" setmarkerpos  [(_pos select 0), (_pos select 1)];

if ((markerColor _marker == side2_MarkerColor) AND (_pos distance friendlybase < _pos distance enemybase) OR (time > 300)) then
{
	// Its closer to us then AI wants it, or if its been left alone for too long.
	// Check if we got the money

	if (_aiSide == side1 AND side1_money > 200 AND side1_ic > 10 AND side1_lc > 20) then
	{
		side1_money = side1_money - 200; side1_ic = side1_ic - 10;side1_lc = side1_lc - 20;
		[_pos,_aiSide] exec "server\coop\bought\commanderOrdered_SF.sqs"; 
	};
	if (_aiSide == side0 AND side0_money > 200 AND side0_ic > 10 AND side0_lc > 20) then
	{
		side1_money = side1_money - 200; side1_ic = side1_ic - 10;side1_lc = side1_lc - 20;
		[_pos,_aiSide] exec "server\coop\bought\commanderOrdered_SF.sqs"; 
	};
};

if ((markerColor _marker == side2_MarkerColor) AND (_pos distance friendlybase > _pos distance enemybase) AND (time < 300) AND (random 10 > 7)) then
{
	if (_aiSide == side1 AND side1_money > 1200 AND side1_ic > 10 AND side1_lc > 20) then
	{
		side1_money = side1_money - 900; side1_ic = side1_ic - 10;side1_lc = side1_lc - 20;
		[_pos,friendlybase,_aiSide] exec "server\coop\bought\commanderOrdered_AirPlanePara.sqs";

	};
	if (_aiSide == side0 AND side0_money > 1200 AND side0_ic > 10 AND side0_lc > 20) then
	{
		side1_money = side1_money - 900; side1_ic = side1_ic - 10;side1_lc = side1_lc - 20;
		[_pos,friendlybase,_aiSide] exec "server\coop\bought\commanderOrdered_Aircav.sqs";
	};
};


